<template>
  <div>
    <a-modal
      centered
      :title="title"
      :width="1000"
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel"
      cancelText="关闭">

      <!-- 查询区域 -->
      <!--<div class="table-page-search-wrapper">
        <a-form layout="inline"  @keyup.enter.native="searchQuery">
          <a-row :gutter="24">

            <a-col :span="10">
              <a-form-item label="用户账号">
                <a-input placeholder="请输入用户账号" v-model="queryParam.username"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="8">
                    <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                      <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                      <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                    </span>
            </a-col>

          </a-row>
        </a-form>
      </div>-->
      <!-- table区域-begin -->
      <div>
        <a-table
          size="small"
          bordered
          rowKey="id"
          :columns="columns1"
          :dataSource="dataSource1"
          :pagination="ipagination"
          :loading="loading"
          :scroll="{ y: 240 }"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type:'radio'}"
          @change="handleTableChange">

        </a-table>
      </div>
      <!-- table区域-end -->


    </a-modal>
  </div>

</template>

<script>
import { getAction, postAction } from '@/api/manage'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import {filterObj} from "@/utils/util";
export default {
  name: "depositPaySign",
  mixins: [JeecgListMixin, mixinDevice],
  data(){
    return{
      model:{},
      fileList:[],
      currentId:'',
      title:'',
      parentFileList:[],
      visible: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
      },
      names: [],
      placement: 'right',
      description: '',
      // 查询条件
      queryParam: {type: "1"},
      //职务条件
      post:'',
      // 表头
      columns1: [
        {
          title: '#',
          dataIndex: '',
          key:'rowIndex',
          width:60,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },
        {
          title:'合同名称',
          align:"center",
          dataIndex: 'name'
        },
        {
          title:'文件大小',
          align:"center",
          dataIndex: 'size'
        },
        {
          title:'文件状态',
          align:"center",
          dataIndex: 'status',
          customRender:function (text) {
            if(text === 0){
              return "文件未上传"
            }else if(text === 1){
              return "文件上传中"
            }else if(text === 2){
              return "文件上传已完成"
            }else if(text === 3){
              return "文件上传失败"
            }else if(text === 4){
              return "文件等待转pdf"
            }else if(text === 5){
              return "文件已转换pdf"
            }else if(text === 6){
              return "加水印中"
            }else if(text === 7){
              return "加水印完毕"
            }else if(text === 8){
              return "文件转换中"
            }else {
              return "文件转换失败"
            }
          }
        },
        {
          title:'合同类型',
          align:"center",
          dataIndex: 'type',
          customRender:function (text) {
            if(text === 1){
              return "订金合同"
            }else {
              return "正式合同"
            }
          }
        }
      ],
      //数据集
      dataSource1: [],
      loading: false,
      selectedRowKeys: [],
      selectedRows: [],
      url: {
        signDeposit: "ghDepositPay/intentionBuy",
        list: "/ghContractFile/list",
      }
    }
  },
  computed: {
    formDisabled(){
      return this.disabled
    },
  },
  created() {
    //this.loadData();
  },
  methods: {
    signDeposit (record) {

    },
    handleCancel() {
      this.visible = false;
    },
    handleOk () {
      if(this.selectedRows[0] === undefined){
        this.$message.error("请选择有效的合同进行签署");
        return;
      }
      // this.$emit("selectFinished", );
      if(this.selectedRows[0].status !== 2 && this.selectedRows[0].status !== 5){
        this.$message.error(this.selectedRows[0].name + "无法用于合同签署");
        return;
      }
      const that = this;
      this.model.fileId = this.selectedRows[0].fileId;
      that.confirmLoading = true;
      postAction(this.url.signDeposit,that.model).then((res)=>{
        if(res.success){
          that.$message.success(res.message);
          that.$emit('ok',that.model.parentId);
        }else{
          that.$message.warning(res.message);
        }
      }).finally(() => {
        this.$emit("selectFinished", this.selectedRows[0]);
        this.selectedRows = [];
        that.confirmLoading = false;
        this.visible = false;
      })
    },
    add() {
      this.visible = true;
    },
    loadContractFileData(arg) {
      var params = this.getQueryParams();//查询条件
      params.type = arg;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource1 = res.result.records;
          this.ipagination.total = res.result.total;
        }
      })
    },
    getQueryParams() {
      var param = Object.assign({}, this.queryParam, this.isorter);
      param.field = this.getQueryField();
      param.pageNo = this.ipagination.current;
      param.pageSize = this.ipagination.pageSize;
      param.post = this.post;
      return filterObj(param);
    },
    getQueryField() {
      //TODO 字段权限控制
    },

    initiateSigning(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
      this.selectedRowKeys = [];
      this.selectionRows = [];
      this.loadContractFileData(record.contractType);
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectionRows
    },

    handleTableChange(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field;
        this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      }
      this.ipagination = pagination;
      this.loadData();
    }
  }
}
</script>

<style scoped>

</style>